<div class="row">
    <div class="col-xs-12">
        <div class="box box-primary">
            <div class="box-header">
                <h3 class="box-title">课表管理</h3>
                <font color="red"> 第 {{ $week }} 周</font>
                <div class="box-tools">
                        <button class="btn btn-success btn-sm" data-url="{{ url('/admin/classes/create') }}" onclick="jumpfun(this)">添加</button>
                </div>
            </div>

            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
                <table class="table table-hover">
                    <tr>
                        <th width="50px">ID</th>
                        <th>星期</th>
                        <th width="200px">时间</th>
                        <th>老师</th>
                        <th>课程年龄</th>
                        <th width="360px">小朋友</th>
                        <th>操作</th>
                    </tr>
                    @foreach($classes as $class)
                    <tr>
                        <td>{{ $class->class_id }}</td>
                        <td>周{{ $class->weekday }}</td>
                        <td>{{ $class->class_time }}</td>
                        <td>{{ $class->teacher_name }}</td>
                        <td>{{ $class->course_age }}岁</td>
                        <td>
                            @if($class->children != null)
                            @foreach($class->children as $child)
                            <a href="javascript:void(0)" data-content="{!! $child['id'] !!}" onclick="childinfo(this)">{{ $child['name'] }} </a> ,
                            @endforeach
                            @endif
                        </td>
                        <td>
                            <a style="margin:3px;" href="javascript:void(0)" data-url="{{ url('/admin/classes', $class->class_id) }}" onclick="jumpfun(this)" class="X-Small btn-xs text-primary"><i class="fa fa-eye"></i> 查看</a>
                            <a style="margin:3px;" href="javascript:void(0)" data-url="{{ url('/admin/child/classes', $class->class_id) }}" onclick="jumpfun(this)" class="X-Small btn-xs text-warning"><i class="fa fa-plus-circle"></i> 添加小朋友</a>
                            <a style="margin:3px;" href="javascript:void(0)" data-url="{{ url('/admin/classes', $class->class_id.'/edit') }}" onclick="jumpfun(this)" class="X-Small btn-xs text-success "><i class="fa fa-edit"></i> 编辑</a>
                            <a style="margin:3px;" href="javascript:void(0)" data-url="{{ url('/admin/classes', $class->class_id) }}" onclick="delfun(this)" class="X-Small btn-xs text-danger "><i class="fa fa-remove"></i> 删除</a>
                        </td>
                    </tr>
                    @endforeach
                </table>
            </div>
            <div class="box-footer clearfix">

            </div>
            <!-- /.box-body -->
        </div>

    </div>
</div>
<div class="modal fade" id="modal-default">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">学生信息</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-2">姓名：</div>
                    <div id="child_name" class="col-md-4"></div>
                </div>
                <div class="row">
                    <div class="col-md-2">小名：</div>
                    <div id="child_nice_name" class="col-md-4"></div>
                </div>
                <div class="row">
                    <div class="col-md-2">性别：</div>
                    <div id="child_sex" class="col-md-4"></div>
                </div>
                <div class="row">
                    <div class="col-md-2">生日：</div>
                    <div id="child_birthday" class="col-md-4"></div>
                </div>
                <div class="row">
                    <div class="col-md-2">家长信息：</div>
                    <div id="child_p_info"></div>
                </div>
                <div class="row">
                    <div class="col-md-2">幼儿园：</div>
                    <div id="child_school"></div>
                </div>
                <div class="row">
                    <div class="col-md-2">来源：</div>
                    <div id="child_source"></div>
                </div>
                <div class="row">
                    <div class="col-md-2">备注：</div>
                    <div id="child_remark"></div>
                </div>
                <div class="row">
                    <div class="col-md-2">创建时间：</div>
                    <div id="child_created_at"></div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="secondModal(this)">调 班</button>
                <button type="button" class="btn btn-default pull-right" data-dismiss="modal">Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<div class="modal modal-primary fade" id="modal-primary">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">调 班</h4>
            </div>
            <div class="modal-body">
                <input class="form-control" id="class_id" name="class_id" placeholder="请填写要调的班级">
                <input type="hidden" id="child_id">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-outline pull-right" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-outline pull-left" onclick="changeClass(this)">Save</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<script>
    function childinfo(obj) {
        var id = $(obj).attr("data-content");
        $.get("/admin/child/findOne/"+id, function (data) {
            var childObj = JSON.parse(data);
            $("#child_name").html(childObj.name);
            $("#child_nice_name").html(childObj.nice_name);
            $("#child_sex").html(childObj.sex?"男":"女");
            $("#child_birthday").html(childObj.birthday);
            $("#child_p_info").html(childObj.p_info);
            $("#child_school").html(childObj.school);
            $("#child_source").html(childObj.source);
            $("#child_remark").html(childObj.remark);
            $("#child_created_at").html(childObj.created_at);
            $("#child_id").val(childObj.id);
        });
        $('#modal-default').modal('show');
    }

    function secondModal(obj) {
        $('#modal-primary').modal('show');
    }

    function changeClass(obj) {
        var c_id = $("#child_id").val();
        var class_id = $("#class_id").val();
        $.post("admin/child/classes/"+class_id, {"c_id":c_id}, function (data) {
            var message = JSON.parse(data);
            if(message.code == 1){
                $('#modal-primary').modal('toggle');
                $('#modal-default').modal('toggle');
                swal("操作成功!", message.msg, "success");
                getContent(message.url);
            }else {
                swal("操作失败!", message.msg, "error");
            }
        })
    }
</script>